package com.dmw.controller;

import com.dmw.Entity.DTO.UserLoginDTO;
import com.dmw.Entity.DTO.UserRegisterDTO;
import com.dmw.Entity.VO.UserLoginVO;
import com.dmw.common.properties.JwtProperties;
import com.dmw.common.result.Result;
import com.dmw.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Tag(name = "用户相关接口")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private JwtProperties jwtProperties;
    /**
     * 用户登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login")
    @Operation(summary = "用户登录接口")
    public Result<UserLoginVO> UserLogin(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户登录，用户名为{}", userLoginDTO.getUsername());
        UserLoginVO vo = userService.login(userLoginDTO);
        return Result.success(vo);
    }

    /**
     * 用户注册
     * @param userRegisterDTO
     * @return
     */
    @PostMapping("/register")
    @Operation(summary = "用户注册接口")
    public Result<UserLoginVO> register(@RequestBody UserRegisterDTO userRegisterDTO) {
        log.info("用户注册，用户名为{}", userRegisterDTO.getUsername());
        UserLoginVO vo = userService.register(userRegisterDTO);
        return Result.success(vo);
    }

}
